/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.unb.graphics;

import br.unb.utils.Console;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.DefaultStyledDocument;

/**
 *
 * @author spider
 */
public class StatusPanel extends JPanel {

    private JTextPane textArea;
    private JScrollPane textScroll;
    
    StatusPanel() {
        super(new BorderLayout());
    }

    public void setDocument(DefaultStyledDocument doc) {
        if (doc != null) {
            textArea = new JTextPane(doc);
            textScroll = new JScrollPane(textArea);

            doc.addDocumentListener(new DocumentListener() {

                public void insertUpdate(DocumentEvent e) {
                    textScroll.getVerticalScrollBar().setValue(
                            textScroll.getVerticalScrollBar().getMaximum());
                }

                public void removeUpdate(DocumentEvent e) {
                    throw new UnsupportedOperationException("Not supported yet.");
                }

                public void changedUpdate(DocumentEvent e) {
                    textScroll.getVerticalScrollBar().setValue(
                            textScroll.getVerticalScrollBar().getMaximum());

                }
            });

            textArea.setEditable(false);
            textScroll.setPreferredSize(new Dimension(80, 80));
            this.add(textScroll);
        } else {
            Console.println("INVALID_DOCUMENT");
        }
    }
}
